<? //include/PRODUCT_session.php

//include("PRODUCT.php");
require_once 'PRODUCT.php';
require_once'../include/database.php';
$conn = new Connection();
$conn->NewConnection('localhost','ecommerce','root','batavia');
class SessionPRODUCT { 


 
 function find($id){
    
   global $conn;
   
   $query = "select ProductID,SKU,SupplierProductID,ProductName,ProductDescription,SupplierID,CategoryID,QuantityPerUnit,UnitSize,UnitPrice,MSRP,AvailableSIze,AvailableColors,SizeID,ColorID,Discount,UnitWeight,UnitInStock,UnitsOnOrder,ReorderLevel,ProductAvailable,DiscountAvailable,CurrentOrder,Picture,Ranking,Note from PRODUCT where ProductID='$id'";
   
   $run = mysql_query($query) or die(mysql_error());
   
   $row = mysql_fetch_array($run, MYSQL_ASSOC);
   
   $numRow = mysql_numrows($run);
   
   if($numRow)
   
   {
   
   $this->PRODUCT= new PRODUCT();


   
	$this->PRODUCT->setProductID($row['ProductID']);

 
	$this->PRODUCT->setSKU($row['SKU']);

 
	$this->PRODUCT->setSupplierProductID($row['SupplierProductID']);

 
	$this->PRODUCT->setProductName($row['ProductName']);

 
	$this->PRODUCT->setProductDescription($row['ProductDescription']);

 
	$this->PRODUCT->setSupplierID($row['SupplierID']);

 
	$this->PRODUCT->setCategoryID($row['CategoryID']);

 
	$this->PRODUCT->setQuantityPerUnit($row['QuantityPerUnit']);

 
	$this->PRODUCT->setUnitSize($row['UnitSize']);

 
	$this->PRODUCT->setUnitPrice($row['UnitPrice']);

 
	$this->PRODUCT->setMSRP($row['MSRP']);

 
	$this->PRODUCT->setAvailableSIze($row['AvailableSIze']);

 
	$this->PRODUCT->setAvailableColors($row['AvailableColors']);

 
	$this->PRODUCT->setSizeID($row['SizeID']);

 
	$this->PRODUCT->setColorID($row['ColorID']);

 
	$this->PRODUCT->setDiscount($row['Discount']);

 
	$this->PRODUCT->setUnitWeight($row['UnitWeight']);

 
	$this->PRODUCT->setUnitInStock($row['UnitInStock']);

 
	$this->PRODUCT->setUnitsOnOrder($row['UnitsOnOrder']);

 
	$this->PRODUCT->setReorderLevel($row['ReorderLevel']);

 
	$this->PRODUCT->setProductAvailable($row['ProductAvailable']);

 
	$this->PRODUCT->setDiscountAvailable($row['DiscountAvailable']);

 
	$this->PRODUCT->setCurrentOrder($row['CurrentOrder']);

 
	$this->PRODUCT->setPicture($row['Picture']);

 
	$this->PRODUCT->setRanking($row['Ranking']);

 
	$this->PRODUCT->setNote($row['Note']);

 
}
return $this->PRODUCT;
}

function insert($PRODUCT){
	global $conn;
	$query = "insert into PRODUCT(ProductID,SKU,SupplierProductID,ProductName,ProductDescription,SupplierID,CategoryID,QuantityPerUnit,UnitSize,UnitPrice,MSRP,AvailableSIze,AvailableColors,SizeID,ColorID,Discount,UnitWeight,UnitInStock,UnitsOnOrder,ReorderLevel,ProductAvailable,DiscountAvailable,CurrentOrder,Picture,Ranking,Note) values('".$PRODUCT->getProductID()."','".$PRODUCT->getSKU()."','".$PRODUCT->getSupplierProductID()."','".$PRODUCT->getProductName()."','".$PRODUCT->getProductDescription()."','".$PRODUCT->getSupplierID()."','".$PRODUCT->getCategoryID()."','".$PRODUCT->getQuantityPerUnit()."','".$PRODUCT->getUnitSize()."','".$PRODUCT->getUnitPrice()."','".$PRODUCT->getMSRP()."','".$PRODUCT->getAvailableSIze()."','".$PRODUCT->getAvailableColors()."','".$PRODUCT->getSizeID()."','".$PRODUCT->getColorID()."','".$PRODUCT->getDiscount()."','".$PRODUCT->getUnitWeight()."','".$PRODUCT->getUnitInStock()."','".$PRODUCT->getUnitsOnOrder()."','".$PRODUCT->getReorderLevel()."','".$PRODUCT->getProductAvailable()."','".$PRODUCT->getDiscountAvailable()."','".$PRODUCT->getCurrentOrder()."','".$PRODUCT->getPicture()."','".$PRODUCT->getRanking()."','".$PRODUCT->getNote()."')";
 
 $parse=mysql_query($query) or die(mysql_error());

 }
 
 function findall(){
	$query = "select ProductID,SKU,SupplierProductID,ProductName,ProductDescription,SupplierID,CategoryID,QuantityPerUnit,UnitSize,UnitPrice,MSRP,AvailableSIze,AvailableColors,SizeID,ColorID,Discount,UnitWeight,UnitInStock,UnitsOnOrder,ReorderLevel,ProductAvailable,DiscountAvailable,CurrentOrder,Picture,Ranking,Note from PRODUCT";
	$parse=mysql_query($query);
	$datas = array();
	while($row=mysql_fetch_assoc($parse))
	{
		$data = array();$data['ProductID'] = $row['ProductID'];
		$data['SKU'] = $row['SKU'];
		$data['SupplierProductID'] = $row['SupplierProductID'];
		$data['ProductName'] = $row['ProductName'];
		$data['ProductDescription'] = $row['ProductDescription'];
		$data['SupplierID'] = $row['SupplierID'];
		$data['CategoryID'] = $row['CategoryID'];
		$data['QuantityPerUnit'] = $row['QuantityPerUnit'];
		$data['UnitSize'] = $row['UnitSize'];
		$data['UnitPrice'] = $row['UnitPrice'];
		$data['MSRP'] = $row['MSRP'];
		$data['AvailableSIze'] = $row['AvailableSIze'];
		$data['AvailableColors'] = $row['AvailableColors'];
		$data['SizeID'] = $row['SizeID'];
		$data['ColorID'] = $row['ColorID'];
		$data['Discount'] = $row['Discount'];
		$data['UnitWeight'] = $row['UnitWeight'];
		$data['UnitInStock'] = $row['UnitInStock'];
		$data['UnitsOnOrder'] = $row['UnitsOnOrder'];
		$data['ReorderLevel'] = $row['ReorderLevel'];
		$data['ProductAvailable'] = $row['ProductAvailable'];
		$data['DiscountAvailable'] = $row['DiscountAvailable'];
		$data['CurrentOrder'] = $row['CurrentOrder'];
		$data['Picture'] = $row['Picture'];
		$data['Ranking'] = $row['Ranking'];
		$data['Note'] = $row['Note'];
		$datas[] = array_merge($data);
                //print_r($data);
	 }
	return $datas;

	}
	function delete($PRODUCT){
	$query = "delete from PRODUCT where ProductID= '".$PRODUCT->getProductID()."'";
	$parse=mysql_query($query);
	return $parse;

	}
	
	function update($PRODUCT){
	$query = "update PRODUCT set SKU= '".$PRODUCT->getSKU()."',SupplierProductID= '".$PRODUCT->getSupplierProductID()."',ProductName= '".$PRODUCT->getProductName()."',ProductDescription= '".$PRODUCT->getProductDescription()."',SupplierID= '".$PRODUCT->getSupplierID()."',CategoryID= '".$PRODUCT->getCategoryID()."',QuantityPerUnit= '".$PRODUCT->getQuantityPerUnit()."',UnitSize= '".$PRODUCT->getUnitSize()."',UnitPrice= '".$PRODUCT->getUnitPrice()."',MSRP= '".$PRODUCT->getMSRP()."',AvailableSIze= '".$PRODUCT->getAvailableSIze()."',AvailableColors= '".$PRODUCT->getAvailableColors()."',SizeID= '".$PRODUCT->getSizeID()."',ColorID= '".$PRODUCT->getColorID()."',Discount= '".$PRODUCT->getDiscount()."',UnitWeight= '".$PRODUCT->getUnitWeight()."',UnitInStock= '".$PRODUCT->getUnitInStock()."',UnitsOnOrder= '".$PRODUCT->getUnitsOnOrder()."',ReorderLevel= '".$PRODUCT->getReorderLevel()."',ProductAvailable= '".$PRODUCT->getProductAvailable()."',DiscountAvailable= '".$PRODUCT->getDiscountAvailable()."',CurrentOrder= '".$PRODUCT->getCurrentOrder()."',Picture= '".$PRODUCT->getPicture()."',Ranking= '".$PRODUCT->getRanking()."',Note= '".$PRODUCT->getNote()."' where ProductID= '".$PRODUCT->getProductID()."'";
$parse=mysql_query($query);

}


}
 //include/PRODUCT_session.php
